<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>楼盘字典更新</title>
<link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">
		<div data-th-replace="~{layout :: header}"></div>
		<div class="layui-body" style="left: 10px;top:10px">
			<h1>请点击你需要更新的楼盘字典数据</h1>
			<div style="margin-top: 10px;">
				<form id="searchFrom" class="layui-form layui-form-pane"
					th:action="@{/estate/update_view}" method="post">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">小区名称</label>
							<div class="layui-input-inline">
								<input name="name" placeholder="小区名称" class="layui-input"
									th:value="${name != null ? name : ''}" maxlength="30">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">操作人</label>
							<div class="layui-input-inline">
								<input name="operator" placeholder="操作人" class="layui-input"
									th:value="${operator != null ? operator : ''}" maxlength="30">
							</div>
						</div>
						<button type="submit" class="layui-btn">搜索</button>
					</div>
				</form>
			</div>
			<!-- 内容主体区域 -->
			<table class="layui-table">
				<colgroup>
					<col width="100">
					<col>
					<col width="100">
					<col width="200">
					<col width="100">
					<col width="200">
					<col width="100">
				</colgroup>
				<thead>
					<tr>
						<th><b>顺序号</b></th>
						<th><b>名称</b></th>
						<th><b>操作人</b></th>
						<th><b>操作时间</b></th>
						<th><b>创建人</b></th>
						<th><b>创建时间</b></th>
						<th><b>操作</b></th>
					</tr>
				</thead>
				<tbody>
					<tr data-th-each="item, iterStat : ${datas}">
						<td data-th-text="${iterStat.count}+${pageIndex-1}*${pageSize}"></td>
						<td data-th-text="${item.name}"></td>
						<td>[[${item.operator}]]</td>
						<td>
							<span th:if="${item.updateTime != null}" class="date">[[${item.updateTime != null ? item.updateTime : '0'}]]</span>
						</td>
						<td>[[${item.creator}]]</td>
						<td data-th-text="${item.createTime}" class="date"></td>
						<td>
							<a class="layui-btn layui-btn-xs" th:onclick="'javascript:updateEstate(' + ${item.id} + ');'">更新</a> 
						</td>
					</tr>
				</tbody>
			</table>

			<div id="pageContent"></div>
		</div>

		<div class="layui-footer">
			<!-- 底部固定区域 -->

		</div>
	</div>
<script th:inline="javascript">
    var contextRoot = /*[[@{/}]]*/ '';
layui.use('laypage', function(){
	  var laypage = layui.laypage;
	  //执行一个laypage实例
	  laypage.render({
		  elem: 'pageContent'
		  ,count:[[${total}]] //数据总数，从服务端得到
		  ,curr: [[${pageIndex}]]	
		  ,layout:['count','prev', 'page', 'next','skip']
		  ,jump: function(obj, first){
			  console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
			    console.log(obj.limit); //得到每页显示的条数
		    //首次不执行
		   if(!first || [[${pageIndex}]] != obj.curr){
		      window.location.href = contextRoot+'/estate/update_view?pageIndex=' + obj.curr + "&pageSize=" + obj.limit +
					      "&" + $("#searchFrom").serialize();
		    } 
		  }
		}); 
	});
function updateEstate(dataId){
	var index = layer.load(1, {time: 1000 * 60 * 30});
	$(".layui-layer-shade").css({"background-color":"#000000","opacity":"0.4"});
	layer.msg("请耐心等待");
	$.ajax({type : "POST",data : {"id":dataId},url : contextRoot+"/estate/update",dataType : "json",
		success : function(msg) {
			if (msg.meta.code == 0) {
				updateLog(msg.data);
			} else {
				layer.msg(msg.meta.message);
			}
			layer.close(index); 
		}
	});
}
function updateLog(htmlText){
	htmlText = "<div style='padding-left:20px;padding-right:20px;'>" + htmlText + "</div>"
	layer.open({
		type: 1,
		resize:false,
		title: "更新说明",
		area: ['90%',"90%"],
		content: htmlText, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
		btn:['确定'],
		yes:function(index){
			window.location.reload();
			layer.close(index); 
		}
	});
}

</script>
</body>
<script type="text/javascript" th:src="@{/common.js}"></script>
</html>